package com.octopus.yangj.customized.controller;

import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import com.octopus.kernal.controller.AbstractValidator;

@Component
public class LoginValidator extends AbstractValidator {
	
	@Override
    public boolean supports(Class<?> aClass) {
        return LoginCommand.class.isAssignableFrom(aClass);
    }

	@Override
    public void validate(Object o, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "error.common.field.empty"
        		, new Object[]{messageSource.getMessage("label.login.username", new Object[]{}, LocaleContextHolder.getLocale())}, "Please specify a username.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.common.field.empty", 
        		new Object[]{messageSource.getMessage("label.login.password", new Object[]{}, LocaleContextHolder.getLocale())}, "Please specify a password.");
    }
}
